package com.woniuxy.controller;

import com.woniuxy.entity.Book;
import com.woniuxy.service.BookService;
import com.woniuxy.util.ResponseData;
import com.woniuxy.util.ResponseEnum;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：CuiYC
 * @description：
 * @date ：Created in 2025/3/7 16:39
 * @modified By：
 */
@RestController
@RequestMapping("/book")
@AllArgsConstructor
//@CrossOrigin(origins = "*")
public class BookController {

    private BookService bookService;

    @GetMapping("/queryAll")
    public ResponseData<?> queryAll() {
        List<Book> books = bookService.queryAll();
        return ResponseData.ok(books);
    }

    @GetMapping("/bookDetail/{id}")
    public ResponseData<?> queryDetail(@PathVariable("id") Integer id) {
        Book book = bookService.queryBookById(id);
        if (book != null) {
            return ResponseData.ok(book);
        }else{
            return ResponseData.fail(ResponseEnum.SYS_BUSY);
        }

    }
}
